package cn.bdqn.controller;

import cn.bdqn.domain.Routes;
import cn.bdqn.service.RoutesService;
import cn.bdqn.utils.result.Page;
import cn.bdqn.utils.result.Result;
import cn.bdqn.utils.result.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 路线控制层
 * @author shaojie
 */
@RestController
public class RoutesController {

    @Autowired
    private RoutesService routesService;

    /**
     * 根据id查询
     * @param id
     * @return
     */
    // ------------------- 服务熔断-----------------
    @GetMapping(value = "/routes/queryByPrimaryKey/{id}")
    public Result queryRoutesByPrimaryKey(@PathVariable("id") Integer id) {
        try {
            return ResultGenerator.genSuccessResult(routesService.queryRoutesByPrimaryKey(id));
        }catch (Exception e){
            e.printStackTrace();
            return ResultGenerator.genFailResult("查询失败");
        }
    }

    /**
     * 选择更新
     * @param record
     */
    // ------------------- 服务熔断-----------------
    @RequestMapping(value = "/routes/updateByPrimaryKeySelective/record")
    public Result updateByPrimaryKeySelective(@RequestBody Routes record) {

        try {
            routesService.updateByPrimaryKeySelective(record);
            return ResultGenerator.genSuccessResult();
        }catch (Exception e){
            e.printStackTrace();
            return ResultGenerator.genFailResult("更新失败");
        }
    }

    /**
     * 多条件查询   分页
     * @param routes
     * @return
     */
    // ------------------- 服务熔断-----------------
    @GetMapping(value = "/routes/queryByVehicle/Routes/pageNum/{pageNum}/pageAmount/{pageAmount}")
    public Result queryByVehicle(@RequestBody Routes routes,@PathVariable("pageNum") Integer pageNum,@PathVariable("pageAmount") Integer pageAmount){

        try {

            Page page = routesService.queryByVehicle(routes,pageNum,pageAmount);

            return ResultGenerator.genSuccessListResult(page.getMenuList(),page.getTotalRecord());

        }catch (Exception e){
            e.printStackTrace();
            return ResultGenerator.genFailResult("查看失败");
        }
    }





}
